a=['alice','david','carolina']
for b in a:
    print(b)

for b in a:
    print(b.title()+', that was a great trick!')
    print("I can't wait to see your next trick, "+b.title()+".\n")

print("Thank you, everyone. That was a great magic show! ")

#创建数字列表
for value in range(1,5):
    print(value)

for value in range(1,6):
    print(value)

numbers=list(range(1,6))
print(numbers)
#指定步长，只打印偶数
even_numbers=list(range(2,11,2))
print(even_numbers)

#前十个整数的平方
squares=[]
for value in range(1,11):
    square=value**2
    squares.append(square)

print(squares)
#
squares=[]
for value in range(1,11):
    squares.append(value**2)
print(squares)
#
digits=[1,2,3,4,5,6,7,8,9,0]
print(min(digits))
print(max(digits))
print(sum(digits))

#列表解析，直接上
squares=[value**2 for value in range(1,11)]
print(squares)

#切片
print(squares[0:3])
print(squares[1:4])
print(squares[:4])
print(squares[2:])
print(squares[-3:])
#
#遍历，也就是循环列表中的一部分
players = ['charles','martina','michael','florence','eli']
print('Here are the first three players on my team: ')
for player in players[:3]:
    print(player.title())

#复制列表，其实就是切片并将值赋给新的列表，原列表不变
my_foods=['pizza','falafel','carrot cake']
friend_foods=my_foods[:]

my_foods.append('cannoli')
friend_foods.append('ice cream')

print("My favorite foods are:")
print(my_foods)

print("\nMy friend's favorite foods are:")
print(friend_foods)

#直接a列表=b列表，ab相关联，a变b变，b变a变

a=[0,1,2,3]
b=a
a.append(4)
b.append(5)
print(a)
print(b)

#元组，不可改变的列表
dimensions=(200,500,1)
print(dimensions)
print(dimensions[1])
print(dimensions[0])

for dimension in dimensions:
    print(dimension)

dimensions=(10,20,30)
print("\nModified dimensions:")
for dimension in dimensions:
    print(dimension)

 #PEP 8代码格式规范



# 0402 第四章的习题前面很简单，最后两道有点难
# 4-1到4-13都很简单，放到第一部分
# 4-14 是要求阅读PEP 8，4-15 缩进，行宽，空行


# 习题 4-1

pizzas=['榴莲芝士披萨','海鲜至尊披萨','黑椒牛肉披萨']

for pizza in pizzas:
    print(pizza)
for pizza in pizzas:
    print(pizza+"超好吃")
print("我是真喜欢必胜客，尤其是白宇哥哥代言之后。")

# 习题 4-2
creatures=['我','你','他']
for creature in creatures:
    print(creature)

for creature in creatures:
    print(creature+'爱吃披萨！')

print('大家都爱吃披萨！')

# 习题 4-3

for n in range(1,21):
    print(n)

# 习题 4-4

# for n in range(1,1000001):
#     print(n)

# 习题 4-5
a=range(1,1000001)

print(min(a))
print(max(a))
print(sum(a))

# 习题 4-6

for odd_number in range(1,20,2):
    print(odd_number)


# 习题4-7 3的倍数，步长为3

for multiple_of_three in range(3,31,3):
    print(multiple_of_three)

# 习题 4-8 立方

b=[]
a=range(1,11)
for n in a:
    b.append(n**3)

print(b)

# 习题 4-9 立方解析

cubic=[n**3 for n in range(1,11)]
print(cubic)

# 4-10 切片

a=range(1,11)

print("\nThe first three items in the list are:\n")

# print(a[:3])

for n in a[0:3]:
    print(n)

print("\nThe items from the middle of the list are:\n")

# print(a[3:6])

for n in a[3:6]:
    print(n)

print("\nThe last three items in the list are:\n")

# print(a[-3:])

for n in a[-3:-1]: #要想去最后一个元素，只能用空，如果用-1，不包含10
    print(n)


# 4-11
pizzas=['榴莲芝士披萨','海鲜至尊披萨','黑椒牛肉披萨']
pizzas_2=pizzas[:]

pizzas.append("巧克力奶茶披萨")
pizzas_2.append("土豆山药披萨")
print("\nMy favorite pizzas are:\n")
print(pizzas)
print("\nMy friend's favorite pizzas are:\n")
print(pizzas_2)

# 4-12

my_foods=['pizza','falafel','carrot cake']
friend_foods=my_foods[:]

my_foods.append('cannoli')
friend_foods.append('ice cream')

print("My favorite foods are:")
# print(my_foods)

for food in my_foods:
    print(food)

print("\nMy friend's favorite foods are:")
# print(friend_foods)
for food in friend_foods:
    print(food)

# 3-13
buffet=('烤肉','冰淇淋','炸鸡','饮料','灌汤包')
for food in buffet:
    print(food)

# buffet(0)='水果'
#can't assign to function call 无法分配给函数调用

buffet=('烤肉','水果','沙拉','饮料','灌汤包')
for food in buffet:
    print(food)
#
# # 4-14 PEP8  https://www.python.org/dev/peps/pep-0008/ 解读
#
# # 4-15
# # PEP 8 是一个编程必须遵守的准则，其中要求每行长度不超过80个字符，我这里用的是Pycharm，所以重点看一下载Pycharm中的设置，https://blog.csdn.net/weixin_42122355/article/details/83373889
# # 函数之间或类的方法之间用空行分隔，表示一段新的代码的开始。类和函数入口之间也用一行空行分隔，以突出函数入口的开始。
# # 空行与代码缩进不同，空行并不是Python语法的一部分。书写时不插入空行，Python解释器运行也不会出错。但是空行的作用在于分隔两段不同功能或含义的代码，便于日后代码的维护或重构。
# # 记住：空行也是程序代码的一部分。